package com.hsytech.dijiebao.account;

import org.json.JSONObject;

import com.hsytech.dijiebao.R;
import com.hsytech.dijiebao.base.BaseActivity;
import com.hsytech.dijiebao.base.BaseApplication;
import com.hsytech.dijiebao.utils.CheckUtils;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SignUpActivity extends BaseActivity {
	private ImageButton top_back_btn;
	private Button bar_right_top_btn;
	private TextView bar_title_tv;
	private EditText email, password, password1, name, phone, nick_name, company, fax;
	private LinearLayout finish, top_bak_liner;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sign_up);

		initView();
	}

	private void initView() {
		initTitle();
		initBody();

	}

	private void initBody() {
		email = (EditText) findViewById(R.id.email);
		password = (EditText) findViewById(R.id.password);
		password1 = (EditText) findViewById(R.id.password1);
		name = (EditText) findViewById(R.id.name);
		phone = (EditText) findViewById(R.id.phone);
		nick_name = (EditText) findViewById(R.id.nick_name);
		company = (EditText) findViewById(R.id.company);
		fax = (EditText) findViewById(R.id.fax);
		finish = (LinearLayout) findViewById(R.id.finish);
		finish.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (checkBeforePost()) {
//					postHttp();
				}
			}
		});
	}

	private void initTitle() {
		top_back_btn = (ImageButton) findViewById(R.id.top_back_btn);
		top_back_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		bar_right_top_btn = (Button) findViewById(R.id.bar_right_top_btn);
		bar_right_top_btn.setVisibility(View.GONE);
		bar_title_tv = (TextView) findViewById(R.id.bar_title_tv);
		bar_title_tv.setText("ע��");
		top_bak_liner = (LinearLayout) findViewById(R.id.top_bak_liner);
		top_bak_liner.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();

			}
		});
	}

	private boolean checkBeforePost() {
		if (email.getText().toString().equals("") || !CheckUtils.isEmail(email.getText().toString().trim())) {
			showToast("����д��ȷ����");
			return false;
		} else if (password.getText().toString().equals("")) {
			showToast("����д����");
			return false;
		} else if (password1.getText().toString().equals("")) {
			showToast("��ȷ������");
			return false;
		} else if (name.getText().toString().equals("")) {
			showToast("����д����");
			return false;
		} else if (phone.getText().toString().equals("")
				|| !CheckUtils.isPhoneNumberValid(phone.getText().toString().trim())) {
			showToast("����д��ȷ�绰");
			return false;
		} else if (nick_name.getText().toString().equals("")) {
			showToast("����д�ǳ�");
			return false;
		} else if (!password.getText().toString().trim().equals(password1.getText().toString().trim())) {
			showToast("�������벻һ��");
			return false;
		} else if (company.getText().toString().trim().equals("")) {
			showToast("��˾����");
			return false;
		} else if (fax.getText().toString().trim().equals("")) {
			showToast("����");
			return false;
		}

		return true;
	}

//	private void postHttp() {
//		// ����
//		BaseApplication.MyDialog.show(this);

//		RequestParams data = new RequestParams();
//		data.put("email", email.getText().toString());
//		data.put("password", password.getText().toString());
//		data.put("name", name.getText().toString());
//		data.put("nickname", nick_name.getText().toString());
//		data.put("mobile", phone.getText().toString());
//		data.put("company", company.getText().toString());
//		data.put("fax", fax.getText().toString());
//
//		CommonHttpUtils.signUpHttp(this, data, new JsonResponseHandler() {
//
//			@Override
//			public void onSuccess(JSONObject data) {
//				showToast("ע��ɹ�");
//				BaseApplication.MyDialog.dismiss();
//				finish();
//			}
//
//			@Override
//			public void onError(String mess) {
//				super.onError(mess);
//
//				showToast(mess);
//				BaseApplication.MyDialog.dismiss();
//			}
//
//			@Override
//			public void onFailure(int statusCode, Throwable throwable) {
//				super.onFailure(statusCode, throwable);
//				Log.d("mylog", "ע��ʧ��");
//				showToast("ע��ʧ��");
//				BaseApplication.MyDialog.dismiss();
//				Log.d("mylog", "throwable" + throwable);
//			}
//
//			@Override
//			public void onFinished() {
//				super.onFinished();
//				BaseApplication.MyDialog.dismiss();
//			}
//		});
//
//	}
}
